package com.yzd.netmonitor.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.joda.time.DateTime;
import org.joda.time.Period;
import org.joda.time.PeriodType;
import org.slf4j.LoggerFactory;

public class DateUtils {

	private static final org.slf4j.Logger logger = LoggerFactory.getLogger(DateUtils.class);

	//计算两个时间之间的毫秒值？
	public static int getCurrentDateLeftSeconds(Date start, Date end) {

		return getCurrentDateLeftSeconds(start.getTime(), end.getTime());
	}

	public static int getCurrentDateLeftSeconds(long start, long end) {

		DateTime s = new DateTime(start);
		DateTime e = new DateTime(end);
		Period p = new Period(s, e, PeriodType.seconds());
		return p.getSeconds();
	}

	public static int getCurrentDateLeftSeconds() {

		Calendar c = Calendar.getInstance();
		//获取当前时间
		long start = c.getTimeInMillis();
		//月日期+1 当前日期+1
		c.add(Calendar.DAY_OF_MONTH, 1);
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		long end = 0;
		try {
			//月日期+1 当前日期+1 毫秒值
			end = format.parse(format.format(c.getTime())).getTime();
		} catch (ParseException e) {
			logger.error(e.getMessage(), e);
		}
		return getCurrentDateLeftSeconds(start, end);
	}

	public static void main(String[] args) {

		logger.info("seconds:{}", getCurrentDateLeftSeconds());
	}
}
